package com.etcn.modules.busi.member.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.etcn.common.service.impl.CrudServiceImpl;
import com.etcn.common.utils.StringUtil;
import com.etcn.common.utils.UploadImageHandler;
import com.etcn.common.utils.UserUtil;
import com.etcn.modules.busi.member.dao.IWmFeedbackDao;
import com.etcn.modules.busi.member.pojo.WmFeedback;
import com.etcn.modules.busi.member.service.IWmFeedbackService;

/**
 * 反馈serviceImpl
 * 
 * @author guozc
 * @date 2018-03-22 10:34:44
 */
@Service("wmFeedbackService")
public class WmFeedbackServiceImpl extends CrudServiceImpl<IWmFeedbackDao, WmFeedback> implements IWmFeedbackService {

	@Autowired
	private UploadImageHandler uploadImageHandler;

	@Override
	public void add(WmFeedback entity) throws Exception {
		// 上传图片
		List<MultipartFile> uploadFile = entity.getUploadFile();
		String imageUrl = "";
		if(uploadFile != null){
			for(MultipartFile file : uploadFile){
				imageUrl += uploadImageHandler.uploadFile(file, "feedback", "feedback-" + System.nanoTime()) + ",";
			}
		}
		// 添加返回
		entity.setMemberId(UserUtil.getCurrentMemberId());
		entity.setCreateTime(new Date());
		if(StringUtil.isNotEmpty(imageUrl)){
			entity.setImageUrl(imageUrl.substring(0, imageUrl.length() -1));
		}
		insert(entity);
	}

}